package com.wn.sddfp.system.listenner;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wn.sddfp.common.model.dto.bank.BankCardAddDTO;
import com.wn.sddfp.common.model.dto.bank.BankCardRequestDto;
import com.wn.sddfp.system.entity.UserCard;
import com.wn.sddfp.system.entity.UserDetail;
import com.wn.sddfp.system.service.IUserCardService;
import com.wn.sddfp.system.service.IUserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

//@Component
public class BindCardListener{

//    @Autowired
//    private IUserDetailService userDetailService;
//
//    @Autowired
//    private IUserCardService userCardService;
//
//    @RabbitListener(
//            queues = "sddfp-queue-bind"
//    )
//    public void bandCardListener(@Payload BankCardRequestDto bankCardRequestDto){
//        String reqCode = bankCardRequestDto.getReqCode();
//        UserDetail userDetail = userDetailService.getOne(Wrappers.lambdaQuery(UserDetail.class).eq(
//                UserDetail::getReqCode,reqCode
//        ));
//        //创建线程   创建线程池大小为 2 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(2);
//
//        //线程1  更新 u_user_detail
//        executorService.submit(()->{
//            //1. 根据请求流水号，更新用户表u_user_detail中绑卡状态 CardBindStatus 把状态进行修改
//
//            userDetail.setCardBindStatus(true);
//            userDetailService.updateById(userDetail);
//
//            System.out.println("修改 user_detail 绑卡状态 ");
//        });
//
//        //线程2  更新 u_user_card
//        executorService.submit(()->{
//            // 2.  根据用户id修改u_user_card绑卡记录表中信息
//            // userDetail.getId() 这个id是 userId
//            UserCard userCard = userCardService.getOne(Wrappers.lambdaQuery(UserCard.class).eq(UserCard::getUserId, userDetail.getId()));
//            userCard.setBankNo(bankCardRequestDto.getBankNo());
//            userCard.setBankTitle(bankCardRequestDto.getBankTitle());
//            //绑卡状态修改
//            userCard.setStatus(true);
//            userCardService.updateById(userCard);
//            System.out.println("修改 u_user_card 绑卡状态 ");
//        });
//
//        //线程关闭
//        executorService.shutdown();
//    }

}